package facade
{{$PluralName := .PluralName}}
{{$AggregatePath := .AggregatePath}}
import (
	"testing"
	"github.com/kataras/iris/v12/httptest"
	"github.com/liuxd6825/dapr-go-ddd-sdk/utils/randomutils"
	"{{.Namespace}}/pkg/cmd-service/userinterface/rest/{{.aggregate_name}}/dto"
    "{{.Namespace}}/pkg/cmd-service/infrastructure/test"
)

func Test{{.Name}}CommandApi(t *testing.T) {
	e := httptest.New(t, app)

	id := randomutils.UUID()
	tenantId := test.TenantId

	{{- range $i, $cmd := .Commands }}
	
	t.Run("{{$cmd.Name}}", func(t *testing.T) {
        req := dto.{{$cmd.Name}}Request{
            CommandId: randomutils.UUID(),
            IsValidOnly: false,
            Data: dto.{{$cmd.Name}}RequestData{
            {{- range $name, $property := $cmd.Fields.Properties }}
                {{- if $property.NameIsId }}
                Id: id,
                {{- else if $property.IsItems }}
                {{- range $v, $itemCode := $property.GoApiTestItemsValue }}
                {{ $itemCode }}
                {{- end }}
                {{- else }}
                {{$name}} : {{$property.GoApiTestValue}},
                {{- end }}
            {{- end }}
            },
        }
        t.Logf("CommandId = %v ", req.CommandId)
        e.{{$cmd.HttpType}}("/api/v1.0/tenants/{tenantId}/{{$AggregatePath}}{{$PluralName}}{{$cmd.HttpCustomMethod}}", tenantId).WithJSON(req).Expect().Status(httptest.StatusOK)
	})

	{{- end }}

    {{- if .IsAggregate }}

	t.Run("FindAggregateById", func(t *testing.T) {
		body := e.GET("/api/v1.0/tenants/{tenantId}/{{$PluralName}}/{id}", tenantId, id).Expect().Status(httptest.StatusOK).Body()
		t.Log(*body)
	})
	{{- end }}

}
